package com.stardata.liangshisq.tcslmon.controller;


import com.stardata.liangshisq.tcslmon.annotation.LoginUser;
import com.stardata.liangshisq.tcslmon.entity.*;
import com.stardata.liangshisq.tcslmon.service.*;
import com.stardata.liangshisq.tcslmon.swagger.ApiResponseObject;
import com.stardata.liangshisq.tcslmon.swagger.ApiResponseProperty;
import com.stardata.liangshisq.tcslmon.swagger.ApiResponseSubProperty;
import com.stardata.liangshisq.tcslmon.util.ApiBaseAction;
import com.stardata.liangshisq.tcslmon.util.R;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Samson Shu
 * @email shush@stardata.top
 * @date 2020/12/15 18:45
 */
@Api(tags = "新版后厨界面接口")
@RestController
@RequestMapping("/v2/{shopId}")
@AllArgsConstructor
public class KitchenControllerV2 extends ApiBaseAction {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private final PrepareService prepareService;
    private final PassonService passonService;
    private final OrderInfoService orderInfoService;
    private final OrderScheduleService orderScheduleService;

    private final TbBizBsTimeService tbBizBsTimeService;

    private final BizBiOrderDayService bizBiOrderDayService;

    @GetMapping("/orders")
    @ApiOperation(value = "查询配菜或传菜界面订单信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "订单信息", properties = {
            @ApiResponseProperty(name = "booking", description = "预定单", type = "list", properties = {
                    @ApiResponseSubProperty(name = "id", description = "订单id", type = "long", example = "1"),
                    @ApiResponseSubProperty(name = "tableNo", description = "桌位编码", type = "string", example = "A02"),
                    @ApiResponseSubProperty(name = "tableName", description = "桌位名称", type = "string", example = "A02桌"),
                    @ApiResponseSubProperty(name = "orderTime", description = "下单时间", type = "datetime", example = "2020-12-02 13:21:00"),
            }),
            @ApiResponseProperty(name = "making", description = "制作中订单", type = "list", properties = {
                    @ApiResponseSubProperty(name = "id", description = "订单id", type = "long", example = "1"),
                    @ApiResponseSubProperty(name = "tableNo", description = "桌位编码", type = "string", example = "A02"),
                    @ApiResponseSubProperty(name = "tableName", description = "桌位名称", type = "string", example = "A02桌"),
                    @ApiResponseSubProperty(name = "orderTime", description = "下单时间", type = "datetime", example = "2020-12-02 13:21:00"),
                    @ApiResponseSubProperty(name = "isJumped", description = "是否插队订单", type = "boolean", example = "true"),
            }),
            @ApiResponseProperty(name = "waiting", description = "等待中订单", type = "list", properties = {
                    @ApiResponseSubProperty(name = "id", description = "订单id", type = "long", example = "1"),
                    @ApiResponseSubProperty(name = "tableNo", description = "桌位编码", type = "string", example = "A02"),
                    @ApiResponseSubProperty(name = "tableName", description = "桌位名称", type = "string", example = "A02桌"),
                    @ApiResponseSubProperty(name = "orderTime", description = "下单时间", type = "datetime", example = "2020-12-02 13:21:00"),
            }),
    })
    public R getOrderInfos(@PathVariable
                           @ApiParam(name = "shopId", value = "店铺ID", required = true, example = "59969") Long shopId,
                           @RequestParam
                           @ApiParam(name = "needPrepared", value = "是否需要已配菜完成的订单（配菜界面不需要，传菜界面需要",
                                   required = true, example = "false") Boolean needPrepared) {

        List<BaseOrderVo> bookingOrders = orderInfoService.queryBooking(shopId);
        List<BaseOrderVo> makingOrders = orderInfoService.queryMaking(shopId, needPrepared);
        List<BaseOrderVo> waitingOrders = orderInfoService.queryWaiting(shopId);

        Map<String, Object> result = new HashMap<>();
        result.put("booking", bookingOrders);
        List<BaseOrderVo> makingNewOrders = new ArrayList<BaseOrderVo>();
        List<BaseOrderVo> waitingNewOrders = new ArrayList<BaseOrderVo>();
        List<Long> bookingIds = new ArrayList<Long>();
        for (BaseOrderVo vo : bookingOrders) {
            bookingIds.add(vo.getId());
        }
        List<Long> waitingIds = new ArrayList<Long>();
        List<Long> makingIds = new ArrayList<Long>();
        for (BaseOrderVo vo : makingOrders) {
            if (bookingIds.contains(vo.getId())) {
                continue;
            } else if (makingNewOrders.size() >= 5 && !vo.getIsJumped()) {
                waitingIds.add(vo.getId());
                waitingNewOrders.add(vo);
                continue;
            } else {
                makingIds.add(vo.getId());
                makingNewOrders.add(vo);
            }
        }

        for (BaseOrderVo vo : waitingOrders) {
            if (vo.getIsJumped()) {
                continue;

            } else if (bookingIds.contains(vo.getId())) {
                continue;
            } else {
                if (waitingIds.contains(vo.getId()) || makingIds.contains(vo.getId())) {
                    continue;
                }
                waitingNewOrders.add(vo);
            }
        }
        result.put("making", makingNewOrders);
        result.put("waiting", waitingNewOrders);
        return success(result);
    }

    @GetMapping("/orders/{bsId}")
    @ApiOperation(value = "查询订单详情列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "订单详情", properties = {
            @ApiResponseProperty(name = "remark", description = "整单备注", type = "string", example = "记得不要放辣"),
            @ApiResponseProperty(name = "list", description = "订单菜品列表", type = "list", properties = {
                    @ApiResponseSubProperty(name = "kscIds", description = "后厨制作流水ID列表", type = "long", example = "【1224234, 1224233]"),
                    @ApiResponseSubProperty(name = "itemId", description = "菜品ID", type = "long", example = "12345"),
                    @ApiResponseSubProperty(name = "itemName", description = "菜品名称", type = "string", example = "水煮鱼"),
                    @ApiResponseSubProperty(name = "origQty", description = "原始下单数量", type = "int", example = "1"),
                    @ApiResponseSubProperty(name = "lastQty", description = "最终下单数量", type = "int", example = "1"),
                    @ApiResponseSubProperty(name = "sourceType", description = "来源类型（1：堂食；2：外卖；3：零售）", type = "int", example = "1"),
                    @ApiResponseSubProperty(name = "tableName", description = "桌号", type = "string", example = "02桌"),
                    @ApiResponseSubProperty(name = "method", description = "做法", type = "string", example = "[\"尖椒\",\"酸甜\"]"),
                    @ApiResponseSubProperty(name = "orderTime", description = "下单时间", type = "datetime", example = "2020-12-02 13:21:00"),
            })
    })
    public R getDetail(@PathVariable
                       @ApiParam(name = "shopId", value = "店铺ID", required = true, example = "59969") Long shopId,
                       @PathVariable
                       @ApiParam(name = "bsId", value = "订单bsId", required = true, example = "1") Long bsId) {
        List<ProductVo> productVos = orderInfoService.queryDetail(bsId);
        Map<String, Object> result = new HashMap<>();
        result.put("list", productVos);
        TbBizBsTime tbBizBsTime = tbBizBsTimeService.getById(bsId);
        String remark = orderInfoService.getOrderRemark(bsId);
        tbBizBsTime.setRemark(remark);
        result.put("bizBs", tbBizBsTime);
        result.put("remark", remark);
        return success(result);
    }

    @GetMapping("/orders/{bsId}/schedule")
    @ApiOperation(value = "查询订单预定信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "订单预定信息", properties = {
            @ApiResponseProperty(name = "bsId", description = "订单bsId", type = "long", example = "1224234"),
            @ApiResponseProperty(name = "scheduled", description = "是否预定", type = "boolean", example = "true"),
            @ApiResponseProperty(name = "time", description = "预定时间", type = "string", example = "12:30"),
    })
    public R getOrderSchedule(@PathVariable
                              @ApiParam(name = "bsId", value = "订单bsId", type = "long",
                                      required = true, example = "11234234234") Long bsId) {
        OrderScheduleVo scheduleInfo = orderScheduleService.getScheduleInfo(bsId);
        if (scheduleInfo == null) {
            scheduleInfo = new OrderScheduleVo();
            scheduleInfo.setBsId(bsId);
            scheduleInfo.setScheduled(false);
        } else {
            scheduleInfo.setScheduled(true);
        }
        return success(scheduleInfo);
    }

    @PostMapping("/orders/{bsId}/schedule")
    @ApiOperation(value = "保存订单预定信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "返回信息")
    public R saveOrderSchedule(@PathVariable
                               @ApiParam(name = "bsId", value = "订单bsId", type = "long",
                                       required = true, example = "11234234234") Long bsId,
                               @RequestBody OrderScheduleVo schedule) {
        schedule.setBsId(bsId);
        if (schedule.getScheduled()) {
            orderScheduleService.saveOrderSchedule(schedule);
        } else {
            orderScheduleService.cancelOrderSchedule(bsId);
        }
        return success();
    }


    @GetMapping("/preparation/window")
    @ApiOperation(value = "查询配菜窗口菜品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "配菜窗口菜品列表", properties = {
            @ApiResponseProperty(name = "itemId", description = "菜品ID", type = "long", example = "12345"),
            @ApiResponseProperty(name = "itemName", description = "菜品名称", type = "string", example = "水煮鱼"),
            @ApiResponseProperty(name = "count", description = "一次切配数量", type = "int", example = "2"),
            @ApiResponseProperty(name = "kscIds", description = "后厨制作流水ID json数组", type = "string", example = "[1224234, 234234]"),
            @ApiResponseProperty(name = "sourceTypes", description = "来源类型json数组（1：堂食；2：外卖；3：零售）", type = "string", example = "[1,2]"),
            @ApiResponseProperty(name = "tableNames", description = "桌号json数组", type = "string", example = "[\"02桌\", \"线上04\",]"),
            @ApiResponseProperty(name = "methods", description = "做法json数组", type = "string", example = "[[\"尖椒\",\"酸甜\"],[],[\"麻辣\"] ]"),
            @ApiResponseProperty(name = "orderTimes", description = "下单时间json数组", type = "string", example = "[\"2020-12-02 13:21:00\",\"2020-12-02 14:15:06\"]"),
            @ApiResponseProperty(name = "isJumpeds", description = "是否插队标记json数组", type = "string", example = "[true, false]"),
    })
    public R getWindowItems(@PathVariable
                            @ApiParam(name = "shopId", value = "店铺ID", type = "long",
                                    required = true, example = "59969") Long shopId,
                            @RequestParam
                            @ApiParam(name = "index", value = "配菜窗口序号", type = "int",
                                    required = true, example = "0") int index) {
        return success(prepareService.queryWindowItems(shopId, index));
    }

    @GetMapping("/preparation/waiting")
    @ApiOperation(value = "查询配菜等待中菜品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "配菜等待中菜品列表", properties = {
            @ApiResponseProperty(name = "kscIds", description = "后厨制作流水ID列表", type = "long", example = "【1224234, 1224233]"),
            @ApiResponseProperty(name = "itemId", description = "菜品ID", type = "long", example = "12345"),
            @ApiResponseProperty(name = "itemName", description = "菜品名称", type = "string", example = "水煮鱼"),
            @ApiResponseProperty(name = "origQty", description = "原始下单数量", type = "int", example = "1"),
            @ApiResponseProperty(name = "lastQty", description = "最终下单数量", type = "int", example = "1"),
            @ApiResponseProperty(name = "sourceType", description = "来源类型（1：堂食；2：外卖；3：零售）", type = "int", example = "1"),
            @ApiResponseProperty(name = "tableName", description = "桌号", type = "string", example = "02桌"),
            @ApiResponseProperty(name = "method", description = "做法", type = "string", example = "[\"尖椒\",\"酸甜\"]"),
            @ApiResponseProperty(name = "orderTime", description = "下单时间", type = "datetime", example = "2020-12-02 13:21:00"),
            @ApiResponseProperty(name = "isJumped", description = "是否插队标记", type = "boolean", example = "true"),
    })
    public R getWaitingItems(@PathVariable
                             @ApiParam(name = "shopId", value = "店铺ID", type = "long",
                                     required = true, example = "59969") Long shopId) {
        return success(prepareService.queryWaitingItems(shopId));
    }

    @PutMapping("/preparation/status")
    @ApiOperation(value = "完成指定ID列表的后厨配菜操作")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "返回信息")
    public R savePrepare(@ApiIgnore @LoginUser DbiEmp loginEmp,
                         @PathVariable
                         @ApiParam(name = "shopId", value = "店铺ID",
                                 required = true, example = "59969") Long shopId,
                         @RequestParam @ApiParam(name = "kscIds", value = "后厨流水id JSON数组",
                                 type = "string", example = "[\"1\",\"2\"]") String kscIds,
                         @RequestParam @ApiParam(name = "prepared", value = "是否完成配菜",
                                 type = "boolean", example = "true") Boolean prepared) {
        List<Long> kscIdList = new ArrayList<>();
        String[] arr = kscIds.split(",");
        for (String s : arr) {
            kscIdList.add(Long.parseLong(s));
        }
        if (kscIdList.size() < 1) {
            return fail(HttpStatus.BAD_REQUEST, "无效的kscIds列表");
        }
        if (prepared == null) {
            return fail(HttpStatus.BAD_REQUEST, "必须指定是否完成配菜");
        }
        prepareService.savePrepareByList(loginEmp.getId(), kscIdList, prepared);
        return success();

    }

    @GetMapping("/passon/cooked")
    @ApiOperation(value = "查询传菜成品熟食菜品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "成品熟食菜品列表", properties = {
            @ApiResponseProperty(name = "kscIds", description = "后厨制作流水ID列表", type = "long", example = "【1224234, 1224233]"),
            @ApiResponseProperty(name = "itemId", description = "菜品ID", type = "long", example = "12345"),
            @ApiResponseProperty(name = "itemName", description = "菜品名称", type = "string", example = "水煮鱼"),
            @ApiResponseProperty(name = "origQty", description = "原始下单数量", type = "int", example = "1"),
            @ApiResponseProperty(name = "lastQty", description = "最终下单数量", type = "int", example = "1"),
            @ApiResponseProperty(name = "sourceType", description = "来源类型（1：堂食；2：外卖；3：零售）", type = "int", example = "1"),
            @ApiResponseProperty(name = "tableName", description = "桌号", type = "string", example = "02桌"),
            @ApiResponseProperty(name = "method", description = "做法", type = "string", example = "[\"尖椒\",\"酸甜\"]"),
            @ApiResponseProperty(name = "orderTime", description = "下单时间", type = "datetime", example = "2020-12-02 13:21:00"),
            @ApiResponseProperty(name = "isJumped", description = "是否插队标记", type = "boolean", example = "true"),
    })
    public R getCookedItems(@PathVariable
                            @ApiParam(name = "shopId", value = "店铺ID", type = "long",
                                    required = true, example = "59969") Long shopId) {
        return success(passonService.queryCookedItems(shopId));
    }

    @GetMapping("/passon/making")
    @ApiOperation(value = "查询传菜制作中菜品列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "传菜制作中菜品列表", properties = {
            @ApiResponseProperty(name = "kscIds", description = "后厨制作流水ID列表", type = "long", example = "【1224234, 1224233]"),
            @ApiResponseProperty(name = "itemId", description = "菜品ID", type = "long", example = "12345"),
            @ApiResponseProperty(name = "itemName", description = "菜品名称", type = "string", example = "水煮鱼"),
            @ApiResponseProperty(name = "status", description = "制作状态（1：配菜中，2：制作中，3：传菜完成，-1：无需后厨制作）", type = "int", example = "1"),
            @ApiResponseProperty(name = "origQty", description = "原始下单数量", type = "int", example = "1"),
            @ApiResponseProperty(name = "lastQty", description = "最终下单数量", type = "int", example = "1"),
            @ApiResponseProperty(name = "sourceType", description = "来源类型（1：堂食；2：外卖；3：零售）", type = "int", example = "1"),
            @ApiResponseProperty(name = "tableNo", description = "桌号编码", type = "string", example = "02"),
            @ApiResponseProperty(name = "tableName", description = "桌号名称", type = "string", example = "02桌"),
            @ApiResponseProperty(name = "method", description = "做法", type = "string", example = "[\"尖椒\",\"酸甜\"]"),
            @ApiResponseProperty(name = "orderTime", description = "下单时间", type = "datetime", example = "2020-12-02 13:21:00"),
            @ApiResponseProperty(name = "operTime", description = "操作时间（如果是'待传菜'状态，则操作时间是配菜时间；如果是'已传菜'状态，则操作时间是配菜时间；）", type = "datetime", example = "2020-12-02 13:21:00"),
            @ApiResponseProperty(name = "isJumped", description = "是否插队标记", type = "boolean", example = "true"),
            @ApiResponseProperty(name = "remark", description = "下单备注", type = "string", example = "先做，大约6点半来取"),
    })
    public R getMakingItems(@PathVariable
                            @ApiParam(name = "shopId", value = "店铺ID", type = "long",
                                    required = true, example = "59969") Long shopId) {
        return success(passonService.queryMakingItems(shopId));
    }

    @PutMapping("/passon/status")
    @ApiOperation(value = "完成指定ID列表的后厨传菜操作")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "返回信息")
    public R savePasson(@ApiIgnore @LoginUser DbiEmp loginEmp,
                        @PathVariable
                        @ApiParam(name = "shopId", value = "店铺ID",
                                required = true, example = "59969") Long shopId,
                        @RequestParam @ApiParam(name = "kscIds", value = "后厨流水id JSON数组",
                                type = "string", example = "[\"1\",\"2\"]") String kscIds,
                        @RequestParam @ApiParam(name = "passed", value = "是否完成传菜",
                                type = "boolean", example = "true") Boolean passed) {
        List<Long> kscIdList = new ArrayList<>();
        String[] arr = kscIds.split(",");
        for (String s : arr) {
            kscIdList.add(Long.parseLong(s));
        }
        if (kscIdList.size() < 1) {
            return fail(HttpStatus.BAD_REQUEST, "无效的kscIds列表");
        }
        if (passed == null) {
            return fail(HttpStatus.BAD_REQUEST, "必须指定是否完成传菜");
        }
        passonService.savePassonByList(loginEmp.getId(), kscIdList, passed);
        return success();
    }

    @PostMapping("/orders/{bsId}/jumping")
    @ApiOperation(value = "保存整单插队")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "返回信息")
    public R saveOrderJumping(@PathVariable
                              @ApiParam(name = "bsId", value = "订单bsId", type = "long",
                                      required = true, example = "11234234234") Long bsId) {
        passonService.jumpOrder(bsId);
        return success();
    }

    @PostMapping("/orders/{bsId}/jumping-items")
    @ApiOperation(value = "保存单品插队")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "返回信息")
    public R saveItemJumping(@PathVariable
                             @ApiParam(name = "bsId", value = "订单bsId", type = "long",
                                     required = true, example = "11234234234") Long bsId,
                             @RequestParam @ApiParam(name = "kscIds", value = "后厨流水id JSON数组",
                                     type = "string", example = "[\"1\",\"2\"]") String kscIds) {
        List<Long> kscIdList = new ArrayList<>();
        String[] arr = kscIds.split(",");
        for (String s : arr) {
            kscIdList.add(Long.parseLong(s));
        }
        if (kscIdList.size() < 1) {
            return fail(HttpStatus.BAD_REQUEST, "无效的kscIds列表");
        }
        passonService.jumpItems(kscIdList);
        return success();
    }

    @GetMapping("/histories/preparation")
    @ApiOperation(value = "查询配菜历史")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "历史配菜记录", properties = {
            @ApiResponseProperty(name = "kscId", description = "后厨制作流水ID", type = "long", example = "1224234"),
            @ApiResponseProperty(name = "itemId", description = "菜品ID", type = "long", example = "12345"),
            @ApiResponseProperty(name = "itemName", description = "菜品名称", type = "string", example = "水煮鱼"),
            @ApiResponseProperty(name = "origQty", description = "原始下单数量", type = "int", example = "1"),
            @ApiResponseProperty(name = "lastQty", description = "最终下单数量", type = "int", example = "1"),
            @ApiResponseProperty(name = "sourceType", description = "来源类型（1：堂食；2：外卖；3：零售）", type = "int", example = "1"),
            @ApiResponseProperty(name = "tableName", description = "桌号", type = "string", example = "02桌"),
            @ApiResponseProperty(name = "method", description = "做法", type = "string", example = "[\"尖椒\",\"酸甜\"]"),
            @ApiResponseProperty(name = "operTime", description = "操作时间", type = "datetime", example = "2020-12-02 13:21:00"),
    })
    public R getPreparationHistory(@PathVariable
                                   @ApiParam(name = "shopId", value = "店铺ID", type = "long",
                                           required = true, example = "59969") Long shopId,
                                   @RequestParam(required = false)
                                   @ApiParam(name = "keyword", value = "查询关键词", type = "string",
                                           example = "黄骨鱼") String keyword) {
        return success(prepareService.queryPrepared(shopId, keyword));
    }

    @GetMapping("/histories/passon")
    @ApiOperation(value = "查询传菜历史")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "历史传菜记录", properties = {
            @ApiResponseProperty(name = "kscId", description = "后厨制作流水ID", type = "long", example = "1224234"),
            @ApiResponseProperty(name = "itemId", description = "菜品ID", type = "long", example = "12345"),
            @ApiResponseProperty(name = "itemName", description = "菜品名称", type = "string", example = "水煮鱼"),
            @ApiResponseProperty(name = "origQty", description = "原始下单数量", type = "int", example = "1"),
            @ApiResponseProperty(name = "lastQty", description = "最终下单数量", type = "int", example = "1"),
            @ApiResponseProperty(name = "sourceType", description = "来源类型（1：堂食；2：外卖；3：零售）", type = "int", example = "1"),
            @ApiResponseProperty(name = "tableName", description = "桌号", type = "string", example = "02桌"),
            @ApiResponseProperty(name = "method", description = "做法", type = "string", example = "[\"尖椒\",\"酸甜\"]"),
            @ApiResponseProperty(name = "operTime", description = "操作时间", type = "datetime", example = "2020-12-02 13:21:00"),
    })
    public R getPassonHistory(@PathVariable
                              @ApiParam(name = "shopId", value = "店铺ID", type = "long",
                                      required = true, example = "59969") Long shopId,
                              @RequestParam(required = false)
                              @ApiParam(name = "keyword", value = "查询关键词", type = "string",
                                      example = "黄骨鱼") String keyword) {
        List<ProductVo> result = passonService.queryPassed(shopId, keyword);
        return success(result);
    }

    @GetMapping("/biz/order/bi")
    @ApiOperation(value = "查询当日的出餐情况")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    public R getBizOrderBi(@PathVariable
                              @ApiParam(name = "shopId", value = "店铺ID", type = "long",
                                      required = true, example = "59969") Long shopId) {
        BizBiOrderDay result = bizBiOrderDayService.getBizOrderBi(shopId);
        return success(result);
    }

    @GetMapping("/histories/ksc")
    @ApiOperation(value = "查询菜品历史")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    @ApiResponseObject(name = "历史传菜记录", properties = {
            @ApiResponseProperty(name = "kscId", description = "后厨制作流水ID", type = "long", example = "1224234"),
            @ApiResponseProperty(name = "itemId", description = "菜品ID", type = "long", example = "12345"),
            @ApiResponseProperty(name = "itemName", description = "菜品名称", type = "string", example = "水煮鱼"),
            @ApiResponseProperty(name = "origQty", description = "原始下单数量", type = "int", example = "1"),
            @ApiResponseProperty(name = "lastQty", description = "最终下单数量", type = "int", example = "1"),
            @ApiResponseProperty(name = "sourceType", description = "来源类型（1：堂食；2：外卖；3：零售）", type = "int", example = "1"),
            @ApiResponseProperty(name = "tableName", description = "桌号", type = "string", example = "02桌"),
            @ApiResponseProperty(name = "method", description = "做法", type = "string", example = "[\"尖椒\",\"酸甜\"]"),
            @ApiResponseProperty(name = "orderCallTime", description = "菜品耗时", type = "long", example = "1223"),
            @ApiResponseProperty(name = "operTime", description = "操作时间", type = "datetime", example = "2020-12-02 13:21:00"),
    })
    public R getKscHistory(@PathVariable
                              @ApiParam(name = "shopId", value = "店铺ID", type = "long",required = true, example = "59969") Long shopId,
                           @RequestParam
                           @ApiParam(name = "needException", value = "是否异常超时菜品信息",
                                   required = true, example = "false") Boolean needException) {
        logger.info("SSS开始时间：{}",LocalDateTime.now());
        List<ProductVo> result = passonService.queryKscHistory(shopId, needException);
        logger.info("SSS结束时间：{}",LocalDateTime.now());
        return success(result);
    }

    @GetMapping("/biz/his/bi")
    @ApiOperation(value = "查询历史的出餐统计情况")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "X-Liangshisq-Token", value = "鉴权token", required = true),
    })
    public R getBizHisBi(@PathVariable
                           @ApiParam(name = "shopId", value = "店铺ID", type = "long",
                                   required = true, example = "59969") Long shopId) {
        List<BizBiOrderDay> result = bizBiOrderDayService.getBizHisBi(shopId);
        return success(result);
    }

}
